import unittest
import os
from case import register_testcase, single_element_testcase, login_testcase, shop_testcase, address_testcase, backstage_check_order_testcase, generate_order_testcase, browser_testcase, addgood_testcase

from HTMLTestRunner import HTMLTestRunner

# 收集测试用例
# 创建加载器

loader = unittest.TestLoader()
# suite = loader.discover('case', pattern='*_testcase.py')
suite1 = loader.loadTestsFromModule(register_testcase)
suite2 = loader.loadTestsFromModule(single_element_testcase)
suite3 = loader.loadTestsFromModule(login_testcase)
suite4 = loader.loadTestsFromModule(shop_testcase)
suite5 = loader.loadTestsFromModule(address_testcase)
suite6 = loader.loadTestsFromModule(backstage_check_order_testcase)
suite7 = loader.loadTestsFromModule(generate_order_testcase)
suite8 = loader.loadTestsFromModule(browser_testcase)
suite9 = loader.loadTestsFromModule(addgood_testcase)


suite1.addTest(suite2)
suite1.addTest(suite3)
suite1.addTest(suite4)
suite1.addTest(suite5)
suite1.addTest(suite6)
suite1.addTest(suite7)
suite1.addTest(suite8)
suite1.addTest(suite9)

with open('report/ecshop_report.html', 'wb') as f:

    # 执行测试报告
    # 把测试结果写入到文件中
    runner = HTMLTestRunner(
        title='ecshop电商系统的Web自动化测试报告',
        description='对测试范围内的模块进行页面自动化测试',
        tester='0721-软件测试-第八组',
        verbosity=2,
        stream=f
    )

    # runner = unittest.TextTestRunner(verbosity=2)
    runner.run(suite1)